package mcsm.GUI.LeftPanel;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import mcsm.GUI.LabelButton;
import mcsm.GUI.MyFrame;
import mcsm.GUI.RightPanel.RightPanel;
import mcsm.GUI.RightPanel.RightPanelFactory;
import mcsm.Model.Staff;

public class ServerLeftPanel extends FunctionLeftPanel {
	ServerLeftPanel(Staff server, int width, int height, MyFrame frame) {
		super(server,width, height, frame);
	}
	
	private class ServerUpPanel extends FunctionUpPanel {
		public ServerUpPanel(int width, int height) {
			super(width, height);
		}		
	}
	
	private class ServerDownPanel extends FunctionDownPanel {
		public ServerDownPanel(int width, int height) {
			super(width, height);
			this.setButtons(2);
		}
		
		@Override
		protected int setOtherLabelsAndSetY() {
			ImageIcon send_nor = new ImageIcon(this.getClass().getResource("/SEED/icon/send_nor.gif"));
			ImageIcon send_sel = new ImageIcon(this.getClass().getResource("/SEED/icon/send_sel.gif"));
			ImageIcon return_nor = new ImageIcon(this.getClass().getResource("/SEED/icon/return_nor.gif"));
			ImageIcon return_sel = new ImageIcon(this.getClass().getResource("/SEED/icon/return_sel.gif"));
			
			LabelButton sendGiftB,returnGoodsB;
			sendGiftB = new LabelButton(x, y, send_nor, send_sel, thisPanel);
			sendGiftB.addMouseListener(new SendGiftButtonListener());
			increaceY();
			returnGoodsB = new LabelButton(x, y, return_nor, return_sel, thisPanel);
			returnGoodsB.addMouseListener(new ReturnButtonListener());
			increaceY();
			
			this.setLayout(null);
			this.add(sendGiftB.getLabel());	
			this.add(returnGoodsB.getLabel());
			
			return y;
		}
	}
	
	protected UpPanel createUpPanel(int width, int height) {
		return new ServerUpPanel(width, height);
	}

	protected DownPanel createDownPanel(int width, int height) {
		return new ServerDownPanel(width, height);
	}
	
	
	private class SendGiftButtonListener extends MouseAdapter {
		public void mouseClicked(MouseEvent e) {
			RightPanel rp = RightPanelFactory.createSendGiftRightPanel( frame);
			frame.setRightPanel(rp);
		}
	}
	
	private class ReturnButtonListener extends MouseAdapter {
		public void mouseClicked(MouseEvent e) {
			RightPanel rp = RightPanelFactory.createReturnGoodsRightPanel(frame, (Staff)person);
			frame.setRightPanel(rp);
		}
	}
}
